package com.sjh.test.java8.base64;

import java.io.UnsupportedEncodingException;
import java.util.Base64;

public class Base64Test2 {

    public static void main(String args[]) {

        try {
            String base64encodedString = Base64.getUrlEncoder().encodeToString(
                    "Java 8 Base64 编码解码 - Java8新特性 - 二哥！ ".getBytes("utf-8"));
            System.out.println(base64encodedString);

            System.out.println();

            byte[] base64decodedBytes = Base64.getUrlDecoder().decode(base64encodedString);

            System.out.println(new String(base64decodedBytes, "utf-8"));

        } catch(UnsupportedEncodingException e) {
            System.out.println("异常：" + e.getMessage());
        }
    }

}
